package com.winston.reflection;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * created by winston on 2024/4/3
 */
public class ReflectionTest {
    static class TargetClass {

//        public TargetClass() {
//
//        }

        private void doSomething(String msg) {
            System.out.println(msg);
        }
    }

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<TargetClass> targetClassClass = TargetClass.class;
        TargetClass targetClass = targetClassClass.getDeclaredConstructor().newInstance();
        Method doSomething = targetClassClass.getDeclaredMethod("doSomething", String.class);
        doSomething.setAccessible(true);
        doSomething
            .invoke(targetClass, "test msg");
    }
}
